package com.xsir.ditan.admin.controller;

import com.wf.captcha.utils.CaptchaUtil;
import com.xsir.ditan.common.config.SystemConfig;
import com.xsir.ditan.miniprogram.common.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Map;

/**
 * @author user
 * @date 2021/2/2
 */
@Slf4j
@Controller
public class LoginController {
    
    /**
     * 登录页面
     */
    @GetMapping("/login")
    public String login(Model model) {
        model.addAttribute("fullName", SystemConfig.fullName);
        return "login";
    }
    
    /**
     * 执行登录请求
     * @param map
     * @return
     */
    @PostMapping("/login")
    @ResponseBody
    public Result login(Map<String, Object> map) {
        
        return Result.ok(null);
    }
    
    /**
     * 获取验证码
     *
     * @param response
     * @return
     */
    @GetMapping("/captcha")
    public void captcha(HttpServletRequest request, HttpServletResponse response) throws Exception {
        CaptchaUtil.out(request, response);
    }
    
}
